<template>
  <div>
    <ShowTable>
      <template #search>
        <!-- <el-tag type="success">搜索区</el-tag> -->
        <el-divider content-position="left">搜索</el-divider>
        <Search @handleChangeSearch="toSearch" />
      </template>
      <template #table>
        <el-divider content-position="left">审核日志列表</el-divider>
        <GoodsCheckLogTable
          :loading="loading"
          :goods-check-log-list.sync="goodsCheckLogList"
          :reverse="reverse"
          :multiple-delete="multipleDelete"
          @hanldeUpdateData="toUpdateData"
        />
      </template>
      <template #paginate>
        <div>
          <Paginate :current-page.sync="currentPage" :page-size.sync="pageSize" :total.sync="total" />
        </div>
      </template>
    </ShowTable>
  </div>
</template>
<script>
import ShowTable from '@/pages/component/laravel-fast-api/v1/showTabel'
import Paginate from '@/pages/component/laravel-fast-api/v1/paginate'

import GoodsCheckLogTable from './goodsCheck/goodsCheckLogTable'
import Search from './goodsCheck/search'

import { getGoodsApplyCheck } from '@/api/youhu-shop/V1/goods/goodsCheck'

export default
{
  // 组件名称
  name: 'GoodsCheckLog',
  // 组件
  components:
    {
      Search,
      ShowTable,
      Paginate,
      GoodsCheckLogTable
    },
  props:
    {
      goods: {
        type: Object,
        default: function()
        {
          return {}
        }
      }
    },
  // 数据
  data()
  {
    return {
      // 配合loading
      loading: true,
      // 弹窗控制
      dialogVisible: false,
      dialogWidth: '98%',
      dialogTitle: '添加',
      // 搜索显示列表条件
      where: {
        goods_id: 0,
        timeRange: [],
        sortType: 2,
        // 0 不导出 1导出
        isExport: 0,
        // 导出类型 1本页 2全部
        exportType: 1,
        // 分页
        currentPage: 1,
        pageSize: 10,
        total: 0
      },
      // 商品审核日志列表容器
      goodsCheckLogList: [],
      // 标记反向选择
      reverse: 0,
      multipleDelete: 0,
      multipleDisable: 0
    }
  },
  // 计算属性
  computed:
    {
      currentPage:
      {
        set(value)
        {
          this.where.currentPage = value
        },
        get()
        {
          return this.where.currentPage
        }
      },
      pageSize:
      {
        set(value)
        {
          this.where.pageSize = value
        },
        get()
        {
          return this.where.pageSize
        }
      },
      total:
      {
        set(value)
        {
          this.where.total = value
        },
        get()
        {
          return this.where.total
        }
      }
    },
  // 监听
  watch:
    {
    },
  // 实例创建之前
  beforeCreate()
  {
  },
  // 创建
  created()
  {
  },
  // 挂载之前
  beforeMount()
  {
  },
  // 挂载 --常用
  mounted()
  {
    this.where.goods_id = this.goods.id
    this.getGoodsApplyCheck(this.where)
  },
  // 更新之前
  beforeUpdate()
  {
  },
  // 跟新后
  updated()
  {
  },
  // 销毁之前
  beforeDestroy()
  {
  },
  // 销毁后
  destroyed()
  {
  },
  // 方法
  methods:
  {
    // 初始化搜索条件
    initPageWhere()
    {
      this.where.isExport = 0
      this.where.exportType = 1
      this.where.currentPage = 1
      this.where.pageSize = 10
      this.where.total = 0
    },

    // 初始化导出状态
    initExport()
    {
      this.where.isExport = 0
      this.where.exportType = 1
    },
    // 更新数据
    toUpdateData()
    {
      this.initExport()
      this.getGoodsApplyCheck(this.where)
    },
    // 查询管理员
    toSearch(param)
    {
      Object.assign(this.where, param)
      this.initPageWhere()
      this.initExport()
      // console.log(this.where)
      this.getGoodsApplyCheck(this.where)
    },
    // 获取商品审核日志
    async getGoodsApplyCheck(where)
    {
      // const replaceData = { current_page: 1, per_page: 10, total: 0, data: [] }
      const goodsApplyCheckList = await getGoodsApplyCheck(where).then(res =>
      {
        return new Promise((resolve, reject) =>
        {
          if (res && res.code === 0)
          {
            if (res.download)
            {
              window.location.href = res.download
            }
            resolve(res)
          }
          else
          {
            reject('获取失败')
          }
        })
      })

      this.where.currentPage = goodsApplyCheckList.meta.current_page
      this.where.pageSize = goodsApplyCheckList.meta.per_page
      this.where.total = goodsApplyCheckList.meta.total
      this.goodsCheckLogList = goodsApplyCheckList.data
      this.loading = false
    },
    handleReverse()
    {
      this.reverse = this.reverse + 1
    },
    handleMultipleDelete()
    {
      this.multipleDelete = this.multipleDelete + 1
    },
    handleMultipleDisable()
    {
      this.multipleDisable = this.multipleDisable + 1
    }
  }
}
</script>
<style lang='scss' scoped>
</style>
